#ifndef P_UNLIT_MATERIAL_SYSTEM_H
#define P_UNLIT_MATERIAL_SYSTEM_H

#include "ECS/Component/Material/PUnlitMaterialComponent.h"
#include "ECS/System/PMaterialSystem.h"

namespace Piccolo
{
#define NUM_MATERIAL_BATCH          16
#define NUM_MATERIAL_BATCH_MAX      2048

    class PiccoloVKPipelineLayout;
    class PiccoloVKPipeline;
    class PiccoloVKDescriptorSetLayout;
    class PiccoloVKDescriptorPool;

    /**
     * 无光照材质system
     */
    class PUnlitMaterialSystem : public PMaterialSystem
    {
    public:
        void OnInit(PiccoloVKRenderPass *renderPass) override;
        void OnRender(VkCommandBuffer cmdBuffer, PiccoloRenderTarget *renderTarget) override;
        void OnDestroy() override;

    private:
        void RecreateMaterialDescriptorPool(uint32_t materialCount);
        void UpdateFrameUBODescriptorSet(PiccoloRenderTarget* renderTarget);
        void UpdateMaterialParamDescriptorSet(VkDescriptorSet descriptorSet, PUnlitMaterial* unlitMaterial);
        void UpdateMaterialResourceDescriptorSet(VkDescriptorSet descriptorSet, PUnlitMaterial* unlitMaterial);

        std::shared_ptr<PiccoloVKDescriptorSetLayout> mFrameUBODescriptorSetLayout;
        std::shared_ptr<PiccoloVKDescriptorSetLayout> mMaterialParamDescriptorSetLayout;
        std::shared_ptr<PiccoloVKDescriptorSetLayout> mMaterialResourceDescriptorSetLayout;

        std::shared_ptr<PiccoloVKPipelineLayout> mPipelineLayout;
        std::shared_ptr<PiccoloVKPipeline> mPipeline;

        std::shared_ptr<PiccoloVKDescriptorPool> mDescriptorPool;
        std::shared_ptr<PiccoloVKDescriptorPool> mMaterialDescriptorPool;

        VkDescriptorSet mFrameUBODescriptorSet;
        std::shared_ptr<PiccoloVKBuffer> mFrameUBOBuffer;

        uint32_t mLastDescriptorSetCount = 0;
        std::vector<VkDescriptorSet> mMaterialDescriptorSetList;
        std::vector<VkDescriptorSet> mMaterialResourceDescriptorSetList;
        std::vector<std::shared_ptr<PiccoloVKBuffer>> mMaterialBuffers;
    };
}

#endif